package com.klangner.go.model.utils;

import com.klangner.go.model.IBoard;

public class BoardUtils {

	/**
	 * Count liberties for single stone
	 * @param x
	 * @param y
	 * @return true if there is at least one liberty
	 */
  public static boolean hasLiberty(IBoard board, int x, int y ) {
      
   	if( x > 0 && board.getStone(x-1, y) == IBoard.NO_STONE) 
  		return true;

    if( x < (board.getSize()-1) && board.getStone(x+1, y) == IBoard.NO_STONE)
    	return true;

   	if( y > 0 && board.getStone(x, y-1) == IBoard.NO_STONE) 
  		return true;

    if( y < (board.getSize()-1) && board.getStone(x, y+1) == IBoard.NO_STONE)
    	return true;

    return false;
  }
  
  /**
   * Change to opposite color
   */
  public static int getOppositeColor(int color){
  	
  	if(color == IBoard.BLACK_STONE)
  		return IBoard.WHITE_STONE;
  	else if(color == IBoard.WHITE_STONE)
  		return IBoard.BLACK_STONE;
  	
  	return color;
  }
  
}
